/*BounceAnimation(弹跳) is used when a sprite fall down to its final position. */
package com.xxxx.game;
import android.graphics.PointF;

public class BounceAnimation extends AnimationBasic implements IObjectPath{
    private PointF mStartPoint;
    private float mUpDistance;
    private int mSteps;
    private int mCurStep;
    private float radio = 0.6f;
    public final static  float UP_DISTANCE = 10.0f;
    public final static int STEP = 4;

    public BounceAnimation(PointF startPoint, float upDis, int steps)
    {
        this.mStartPoint = startPoint;
        this.mUpDistance = upDis;
        this.mSteps = steps;
        this.mCurStep = 0;
    }

    @Override
    public PointF getCurPoint() {
        PointF currentPoint = new PointF(0,0);
        if (mCurStep / mSteps < 0.6)//jump up
        {   float dy = mUpDistance / (mSteps * radio);
            currentPoint.x = mStartPoint.x;
            currentPoint.y = mStartPoint.y - mCurStep * dy;
        }
        else//jump down
        {
            float dy = mUpDistance / (mSteps * (1 - radio));
            currentPoint.x = mStartPoint.x;
            currentPoint.y = mStartPoint.y - (mSteps - mCurStep)* dy;
        }
        return currentPoint;
    }
    @Override
    public PointF update(PointF curPt) {
        if (mCurStep < mSteps)
            mCurStep++;
        return getCurPoint();
    }

    @Override
    public boolean update(ISprite sprite) {
        if (sprite != null)
            sprite.setPosition(this.update(sprite.getPosition()));
        return isMoving();
    }

    @Override
    public String getName() {
        return "Bounce";
    }

    @Override
    public boolean isMoving() {
        return mCurStep < mSteps;
    }
}
